app.controller("LogonForm", function($scope, $location, AuthService)
{
	$scope.Error = false;
	$scope.ErrorInfo = "";
	$scope.ButtonInfo = "登录";
	$scope.buttondisabled = false;
	$scope.onLogon = function()
	{
		var form = $( ".login-form" );
		if (form.valid()) {
			$scope.ButtonInfo = "正在登录...";
			$scope.buttondisabled = true;
			AuthService.logon(
			{
				'username' : $scope.username,
				'password' : $scope.password
			}).success(function(data, status, headers, config) 
			{
				if (data.success)
				{
					var mainUrl = $location.protocol() + ":\\\\" + $location.host() + ":" + $location.port() + "/main.html";
					window.location.replace( mainUrl );
				}
				else
				{
					$scope.Error = true;
					$scope.ErrorInfo = data.errorinfo;
					$scope.ButtonInfo = "登录";
					$scope.buttondisabled = false;
				}
			}).error(function(data, status, headers, config) {
				$scope.ButtonInfo = "登录";
			});
		};
		
	}
	
});